$OpenBSD: patch-engine_c,v 1.2 2015/11/21 01:51:50 sthen Exp $
--- engine.c.orig	Wed Nov  7 06:35:44 2007
+++ engine.c	Sat Nov 21 01:51:04 2015
@@ -34,11 +34,11 @@
 #endif
 
 /* circular linked list of views */
-CIRCLEQ_HEAD(view_list, view_ent) view_head =
-				  CIRCLEQ_HEAD_INITIALIZER(view_head);
+TAILQ_HEAD(view_list, view_ent) view_head =
+				  TAILQ_HEAD_INITIALIZER(view_head);
 struct view_ent {
 	field_view *view;
-	CIRCLEQ_ENTRY(view_ent) entries;
+	TAILQ_ENTRY(view_ent) entries;
 };
 
 int delay = 5;
@@ -510,7 +510,7 @@ add_view(field_view *fv)
 		return;
 
 	ent->view = fv;
-	CIRCLEQ_INSERT_TAIL(&view_head, ent, entries);
+	TAILQ_INSERT_TAIL(&view_head, ent, entries);
 
 	if (curr_view == NULL)
 		set_curr_view(ent);
@@ -526,7 +526,7 @@ set_view(char *opt)
 	if (opt == NULL || (len = strlen(opt)) == 0)
 		return 1;
 
-	CIRCLEQ_FOREACH(ve, &view_head, entries) {
+	TAILQ_FOREACH(ve, &view_head, entries) {
 		v = ve->view;
 		if (strncasecmp(opt, v->name, len) == 0) {
 			if (vm)
@@ -548,7 +548,7 @@ foreach_view(void (*callback)(field_view *))
 {
 	struct view_ent *ve;
 
-	CIRCLEQ_FOREACH(ve, &view_head, entries) {
+	TAILQ_FOREACH(ve, &view_head, entries) {
 		callback(ve->view);
 	}
 }
@@ -560,7 +560,7 @@ set_view_hotkey(int ch)
 	field_view *v;
 	int key = tolower(ch);
 
-	CIRCLEQ_FOREACH(ve, &view_head, entries) {
+	TAILQ_FOREACH(ve, &view_head, entries) {
 		v = ve->view;
 		if (key == v->hotkey) {
 			set_curr_view(ve);
@@ -576,12 +576,12 @@ next_view(void)
 {
 	struct view_ent *ve;
 
-	if (CIRCLEQ_EMPTY(&view_head) || curr_view_ent == NULL)
+	if (TAILQ_EMPTY(&view_head) || curr_view_ent == NULL)
 		return;
 
-	ve = CIRCLEQ_NEXT(curr_view_ent, entries);
-	if (ve == CIRCLEQ_END(&view_head))
-		ve = CIRCLEQ_FIRST(&view_head);
+	ve = TAILQ_NEXT(curr_view_ent, entries);
+	if (ve == NULL)
+		ve = TAILQ_FIRST(&view_head);
 
 	set_curr_view(ve);
 }
@@ -591,12 +591,12 @@ prev_view(void)
 {
 	struct view_ent *ve;
 
-	if (CIRCLEQ_EMPTY(&view_head) || curr_view_ent == NULL)
+	if (TAILQ_EMPTY(&view_head) || curr_view_ent == NULL)
 		return;
 
-	ve = CIRCLEQ_PREV(curr_view_ent, entries);
-	if (ve == CIRCLEQ_END(&view_head))
-		ve = CIRCLEQ_LAST(&view_head);
+	ve = TAILQ_PREV(curr_view_ent, view_list, entries);
+	if (ve == NULL)
+		ve = TAILQ_LAST(&view_head, view_list);
 
 	set_curr_view(ve);
 }
@@ -808,6 +808,9 @@ void
 next_order(void)
 {
 	order_type *o, *oc;
+
+	if (curr_view->mgr->order_list == NULL)
+		return;
 
 	oc = curr_view->mgr->order_curr;
 
